<?php
namespace Hilaoyu\ComputeCloudClient\Api;


use AlibabaCloud\SDK\Cbn\V20170912\Models\CreateCenRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\AssociateEipAddressRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\CreateRouteEntryRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DeleteRouteEntryRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\AllocateEipAddressRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\AssociateRouteTableRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\CreateRouteTableRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\CreateVpcRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\CreateVSwitchRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DeleteRouteTableRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DeleteVpcRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DeleteVSwitchRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeEipAddressesRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeRegionsRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeRouteEntryListRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeRouteTableListRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeVpcsRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeVSwitchesRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\DescribeZonesRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\ModifyEipAddressAttributeRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\ReleaseEipAddressRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\UnassociateEipAddressRequest;
use AlibabaCloud\SDK\Vpc\V20160428\Models\UnassociateRouteTableRequest;
use AlibabaCloud\Tea\Model;
use Hilaoyu\ComputeCloudClient\AssetModel;
use Hilaoyu\ComputeCloudClient\AssetModels;
use Hilaoyu\ComputeCloudClient\Interfaces\ApiVpcInterface;
use Hilaoyu\Utils\UtilArr;
use Hilaoyu\ComputeCloudClient\AliyunApi;

/**
 * Class AliVpc
 * @package Hilaoyu\ComputeCloudClient\Api
 * @property  \AlibabaCloud\SDK\Vpc\V20160428\Vpc $client
 */
class AliVpc extends AliApiBase implements ApiVpcInterface
{

    public function regionsDescribe( ):array
    {
        $models = [];
        try{
            $request = new DescribeRegionsRequest([]);
            $result = $this->client->describeRegions($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'Regions.Region');

            foreach ($data as $datum){
                $id = UtilArr::get($datum,'RegionId');
                if(!$id){
                    continue;
                }
                $models[] = ["id"=>$id,"name"=>UtilArr::get($datum,'LocalName')];
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }
    public function zonesDescribe($regionId=''):array
    {
        $regionId = $this->getRegionId($regionId);
        $models = [];
        if(!$regionId){
            return [];
        }
        try{
            $request = new DescribeZonesRequest([
                'regionId'        => $regionId,
            ]);
            $result = $this->client->describeZones($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'Zones.Zone');

            foreach ($data as $datum){
                $id = UtilArr::get($datum,'ZoneId');
                if(!$id){
                    continue;
                }
                $models[] = ["id"=>$id,"name"=>UtilArr::get($datum,'LocalName')];
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }

    public function vpcsDescribe(string $vpcId=null,string $vpcname=null,$regionId=''):AssetModels
    {
        $regionId = $this->getRegionId($regionId);
        $models = new AssetModels();
        try{
            $request = new DescribeVpcsRequest([
                'regionId'        => $regionId,
                'vpcId'        => $vpcId,
                'vpcName'        => $vpcname,
            ]);
            $result = $this->client->describeVpcs($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'Vpcs.Vpc');

            foreach ($data as $datum){
                $id = UtilArr::get($datum,'VpcId');
                if(!$id){
                    continue;
                }

                $model = new AssetModel();
                $model->type ='vpc';
                $model->asset_id = $id;
                $model->region_id = UtilArr::get($datum,'RegionId');
                $model->name = UtilArr::get($datum,'VpcName');
                $model->network = UtilArr::get($datum,'CidrBlock');
                $model->status = UtilArr::get($datum,'Status');


                $models->push($model);
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }

    public function vpcDescribe(string $vpcId,$regionId=''):?AssetModel
    {
        $models = $this->vpcsDescribe($vpcId,null,$regionId);
        if(!$models){
            return null;
        }

        return $models->first(function ($item) use ($vpcId){
            return $item->asset_id == $vpcId;
        });
    }

    public function vpcCreate($vpcname=null,$network=null,$ipv6Network=null,$regionId='',$resourceGroupId=null):?AssetModel
    {
        $regionId = $this->getRegionId($regionId);

        try{
            if($vpcname){
                $hasVpcs = $this->vpcsDescribe($vpcname,$regionId);

                if($hasVpcs && $hasVpcs->count() > 0){
                    throw new \Exception('vpcname is exists');
                }
            }
            $request = new CreateVpcRequest([
                'regionId'        => $regionId,
                'vpcName'        => $vpcname,
                'resourceGroupId'        => $resourceGroupId,
                'cidrBlock'        => $network,
                'ipv6CidrBlock'        => $ipv6Network,
                'enableIpv6'        => $ipv6Network ? 'true' : 'false',
            ]);
            $result = $this->client->createVpc($request);

            $datum = $result->body->toMap();
            $id = UtilArr::get($datum,'VpcId');
            if(!$id){
                throw new \Exception('返回数据错误');
            }

            $model = new AssetModel();
            $model->type ='vpc';
            $model->asset_id = $id;
            $model->region_id = (string)$regionId;
            $model->name = (string)$vpcname;
            $model->network = (string)$network;
            $model->status = 'Pending';
            return $model;
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }

        return null;
    }

    public function vpcDelete($vpcId,$regionId=''):bool
    {
        $regionId = $this->getRegionId($regionId);
        $vpcId = trim($vpcId);
        if(!$vpcId){
            return false;
        }
        if(!$this->vpcDescribe($vpcId)){
            return true;
        }

        try{
            $request = new DeleteVpcRequest([
                'regionId'        => $regionId,
                'vpcId'        => $vpcId,
            ]);
            $result = $this->client->deleteVpc($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }

    public function vSwitchCreate($vpcId,$zoneId,$network,$vSwitchName=null,$ipv6Network=null,$regionId=''):?AssetModel
    {
        $regionId = $this->getRegionId($regionId);
        $zoneId = trim($zoneId);
        $vpcId = trim($vpcId);
        $vSwitchName = trim($vSwitchName);

        if(!$vpcId){
            return null;
        }
        try{
            $request = new CreateVSwitchRequest([
                'zoneId'        => $zoneId,
                'regionId'        => $regionId,
                'vpcId'        => $vpcId,
                'cidrBlock'            => $network,
                'vSwitchName'            => $vSwitchName,
                'ipv6CidrBlock'        => $ipv6Network,
            ]);
            $result = $this->client->createVSwitch($request);

            $datum = $result->body->toMap();
            $id = UtilArr::get($datum,'VSwitchId');
            if(!$id){
                throw new \Exception('返回数据错误');
            }

            $model = new AssetModel();
            $model->type ='vsw';
            $model->asset_id = $id;
            $model->region_id = (string)$regionId;
            $model->name = (string)$vSwitchName;
            $model->network = (string)$network;
            $model->bind_asset_id = (string)$vpcId;
            $model->status = 'Pending';
            return $model;
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return null;
    }

    public function vSwitchDelete($vSwitchId,$regionId=''):bool{
        $regionId = $this->getRegionId($regionId);
        $vSwitchId = trim($vSwitchId);

        if(!$vSwitchId){
            return false;
        }
        if(!$this->vSwitchDescribe($vSwitchId)){
            return true;
        }
        try{
            $request = new DeleteVSwitchRequest([
                'regionId'        => $regionId,
                'vSwitchId'        => $vSwitchId,
            ]);
            $result = $this->client->deleteVSwitch($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;

    }
    public function vSwitchsDescribe($vSwitchId=null,$vSwitchName=null,$vpcId=null,$regionId=''):AssetModels
    {
        $regionId = $this->getRegionId($regionId);
        $models = new AssetModels();
        try{
            $request = new DescribeVSwitchesRequest([
                'regionId'        => $regionId,
                'vSwitchId'        => $vSwitchId,
                'vSwitchName'        => $vSwitchName,
                'vpcId'        => $vpcId,
            ]);
            $result = $this->client->describeVSwitches($request);


            $data = (array)UtilArr::get($result->body->toMap(), 'VSwitches.VSwitch');

            foreach ($data as $datum){
                $id = UtilArr::get($datum,'VSwitchId');
                if(!$id){
                    continue;
                }

                $model = new AssetModel();
                $model->type ='vsw';
                $model->asset_id = $id;
                $model->region_id = (string)$regionId;
                $model->name = UtilArr::get($datum,'VSwitchName');
                $model->bind_asset_id = UtilArr::get($datum,'VpcId');
                $model->network = UtilArr::get($datum,'CidrBlock');
                $model->status = UtilArr::get($datum,'Status');
                $model->vsw_vtb = UtilArr::get($datum,'RouteTable.RouteTableId');


                $models->push($model);
            }
            return $models;
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        $models = new AssetModels();
    }

    public function vSwitchDescribe($vSwitchId,$regionId=''):?AssetModel
    {
        $models = $this->vSwitchsDescribe($vSwitchId,null,null,$regionId);
        if(!$models){
            return null;
        }

        return  $models->first(function ($item) use ($vSwitchId){
            return $item->asset_id == $vSwitchId;
        });

    }


    //EIP

    /**
     * @param int $bandwidth EIP的带宽峰值，取值范围：1~200，单位为Mbps
     * @param string $instanceChargeType EIP的计费方式，取值： PrePaid：包年包月。 PostPaid（默认值）：按量计费。; 当InstanceChargeType取值为PrePaid时，InternetChargeType必须取值PayByBandwidth；当InstanceChargeType取值为PostPaid时，InternetChargeType可取值PayByBandwidth或PayByTraffic
     * @param string $internetChargeType EIP的计量方式，取值： PayByBandwidth（默认值）：按带宽计费。 PayByTraffic：按流量计费。; 当InstanceChargeType取值为PrePaid时，InternetChargeType必须取值PayByBandwidth。;当InstanceChargeType取值为PostPaid时，InternetChargeType可取值PayByBandwidth或PayByTraffic。
     * @param string $isp 线路类型 BGP：BGP（多线）线路。BGP_PRO：BGP（多线）精品线路
     * @param string $pricingCycle 包年包月的计费周期，取值：Month（默认值）：按月付费。Year：按年付费;当InstanceChargeType参数的值为PrePaid时，该参数必选；当InstanceChargeType参数的值为PostPaid时，该参数可不填
     * @param int $period 购买时长。 当PricingCycle取值Month时，Period取值范围为1~9。  当PricingCycle取值Year时，Period取值范围为1~5。  如果InstanceChargeType参数的值为PrePaid时，该参数必选，如果InstanceChargeType参数的值为PostPaid时，该参数不填。
     * @param string $regionId
     * @param null $resourceGroupId 资源组ID
     * @return AssetModel
     */
    public function eipAddressAllocate(int $bandwidth=50,string $instanceChargeType='PostPaid',string $internetChargeType='PayByTraffic',string $isp='BGP',string $pricingCycle='',int $period=null,string $name=null,$regionId = '',$resourceGroupId=null):?AssetModel
    {
        $regionId = $this->getRegionId($regionId);
        $bandwidth = intval($bandwidth);
        try {
            $request = new AllocateEipAddressRequest([
                'regionId' => $regionId,
                'bandwidth' => $bandwidth,
                'pricingCycle' => $pricingCycle,
                'period' => $period,
                'instanceChargeType' => $instanceChargeType,
                'internetChargeType' => $internetChargeType,
                'ISP' => $isp,
                'name' => $name,
            ]);
            $result = $this->client->allocateEipAddress($request);


            $datum = $result->body->toMap();
            $id = UtilArr::get($datum,'AllocationId');
            if(!$id){
                throw new \Exception('返回数据错误');
            }

            $model = new AssetModel();
            $model->type ='eip';
            $model->asset_id = $id;
            $model->region_id = (string)$regionId;
            $model->primary_ip = UtilArr::get($datum,'EipAddress');
            $model->name = $model->primary_ip;
            $model->bandwidth = $bandwidth;
            $model->instance_type = $isp;
            $model->status = 'Pending';
            return $model;
        } catch (\Exception $exception) {
            $this->setError($exception->getMessage());
        }
        return null;
    }
    public function eipAddressUpdate(string $allocationId,string $name=null,int $bandwidth=50,$regionId = ''):?AssetModel
    {
        $regionId = $this->getRegionId($regionId);
        $name = trim($name);
        $bandwidth = intval($bandwidth);
        try {
            $model = $this->eipAddressDescribe($allocationId);
            if(!$model){
                throw new \Exception('eip不存在');

            }
            $data =[
                'regionId' => $regionId,
                'allocationId' => $allocationId,
                'name' => $name,
            ];

            if($bandwidth > 0 ){
                $data['bandwidth'] = $bandwidth;
            }
            if($name ){
                $data['name'] = $name;
            }
            $request = new ModifyEipAddressAttributeRequest();
            $result = $this->client->modifyEipAddressAttribute($request);

            if(!(bool)$result->body->toMap()){
                throw new \Exception('返回数据错误');
            }
            if($bandwidth > 0 ){
                $model->bandwidth = $bandwidth;
            }
            if($name ){
                $model->name = $name;
            }
            return $model;
        } catch (\Exception $exception) {
            $this->setError($exception->getMessage());
        }
        return null;
    }
    public function eipAddressRelease(string $allocationId, $regionId = ''):bool
    {
        if(!$this->eipAddressDescribe($allocationId,null,$regionId)){
            return true;
        }
        $regionId = $this->getRegionId($regionId);
        try {
            $request = new ReleaseEipAddressRequest([
                'regionId' => $regionId,
                'allocationId' => $allocationId,
            ]);
            $result = $this->client->releaseEipAddress($request);

            return (bool)$result->body->toMap();
        } catch (\Exception $exception) {
            $this->setError($exception->getMessage());
        }
        return false;
    }

    public function eipAddressAssociate(string $allocationId, string $instanceId, string $instanceType=null,$regionId = ''):bool
    {
        $regionId = $this->getRegionId($regionId);

        try {
            $request = new AssociateEipAddressRequest([
                'regionId' => $regionId,
                'instanceId' => $instanceId,
                'allocationId' => $allocationId,
                'instanceType' => $instanceType,
            ]);
            $result = $this->client->associateEipAddress($request);

            return (bool)$result->body->toMap();;
        } catch (\Exception $exception) {
            $this->setError($exception->getMessage());
        }
        return false;
    }

    public function eipAddressUnassociate( string $allocationId,string $instanceId=null, $regionId = ''):bool
    {
        $regionId = $this->getRegionId($regionId);

        try {
            $request = new UnassociateEipAddressRequest([
                'regionId' => $regionId,
                'instanceId' => $instanceId,
                'allocationId' => $allocationId,
            ]);
            $result = $this->client->unassociateEipAddress($request);

            return (bool)$result->body->toMap();;
        } catch (\Exception $exception) {
            $this->setError($exception->getMessage());
        }
        return false;
    }


    public function eipAddressesDescribe(string $allocationId=null,string $eipAddress=null,string $status=null,$regionId=''):AssetModels
    {
        $regionId = $this->getRegionId($regionId);
        $models = new AssetModels();
        try{
            $request = new DescribeEipAddressesRequest([
                'regionId'        => $regionId,
                'allocationId'        => $allocationId,
                'eipAddress'        => $eipAddress,
                'status'        => $status,
            ]);
            $result = $this->client->describeEipAddresses($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'EipAddresses.EipAddress');
            //dump($data);
            foreach ($data as $datum){
                $id = UtilArr::get($datum,'AllocationId');
                if(!$id){
                    continue;
                }

                $model = new AssetModel();
                $model->type ='eip';
                $model->asset_id = $id;
                $model->region_id = (string)$regionId;
                $model->primary_ip = UtilArr::get($datum,'IpAddress');
                $model->name = $model->primary_ip;
                $model->bind_asset_id = trim(UtilArr::get($datum,'InstanceId'));
                $model->os_type = trim(UtilArr::get($datum,'InstanceType'));
                $model->instance_type = UtilArr::get($datum,'ISP');
                $model->bandwidth = UtilArr::get($datum,'Bandwidth');
                $model->status = UtilArr::get($datum,'Status');
                $models->push($model);
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }

    public function eipAddressDescribe(string $allocationId, string $eipAddress = null,$regionId=''):?AssetModel
    {
        $models = $this->eipAddressesDescribe($allocationId,$eipAddress,null,$regionId);
        if(!$models){
            return null;
        }

        return $models->first(function ($item) use ($allocationId,$eipAddress){
            return $item->asset_id == $allocationId || $item->primary_ip == $eipAddress;
        });

    }



    //路由表
    public function routeTableCreate($vpcId,$routeTableName=null,$regionId=''):?AssetModel
    {
        $regionId = $this->getRegionId($regionId);
        $vpcId = trim($vpcId);
        $routeTableName = trim($routeTableName);

        if(!$vpcId){
            return null;
        }
        try{
            $request = new CreateRouteTableRequest([
                'regionId'        => $regionId,
                'vpcId'        => $vpcId,
                'routeTableName'            => $routeTableName,
            ]);
            $result = $this->client->createRouteTable($request);

            $datum = $result->body->toMap();
            $id = UtilArr::get($datum,'RouteTableId');
            if(!$id){
                throw new \Exception('返回数据错误');
            }

            $model = new AssetModel();
            $model->type ='vtb';
            $model->asset_id = $id;
            $model->region_id = (string)$regionId;
            $model->name = (string)$routeTableName;

            $model->os_type = 'Custom';
            $model->status = 'Pending';
            return $model;
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return null;
    }
    public function routeTableDelete($routeTableId,$regionId=''):bool
    {
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);

        if(!$routeTableId){
            return false;
        }

        if(!$this->routeTableDescribe($routeTableId)){
            return true;
        }
        try{
            $request = new DeleteRouteTableRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
            ]);
            $result = $this->client->deleteRouteTable($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }
    public function routeTablesDescribe(string $routeTableId=null,string $vpcId=null,$regionId=''):AssetModels
    {
        $regionId = $this->getRegionId($regionId);
        $models = new AssetModels();
        try{
            $request = new DescribeRouteTableListRequest([
                'regionId'        => $regionId,
                'vpcId'        => $vpcId,
                'routeTableId'        => $routeTableId,
            ]);
            $result = $this->client->describeRouteTableList($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'RouterTableList.RouterTableListType');
            foreach ($data as $datum){
                $id = UtilArr::get($datum,'RouteTableId');
                if(!$id){
                    continue;
                }

                $model = new AssetModel();
                $model->type ='vtb';
                $model->asset_id = $id;
                $model->region_id = (string)$regionId;
                $model->name = UtilArr::get($datum,'RouteTableName');
                $model->os_type = UtilArr::get($datum,'RouteTableType');
                $vswIds = UtilArr::get($datum,'VSwitchIds');
                $model->status = UtilArr::get($datum,'Status') . (empty($vswIds) ?'NotUse':'InUse');
                $models->push($model);
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }

    public function routeTableDescribe(string $routeTableId,$regionId=''):?AssetModel
    {
        $models = $this->routeTablesDescribe($routeTableId,null,$regionId);
        if(!$models){
            return null;
        }

        return $models->first(function ($item) use ($routeTableId){
            return $item->asset_id == $routeTableId;
        });

    }

    public function routeTableAssociate(string $routeTableId,string $vSwitchId,$regionId=''):bool{
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);
        $vSwitchId = trim($vSwitchId);
        if(!$routeTableId || !$vSwitchId){
            return false;
        }
        try{
            $request = new AssociateRouteTableRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
                'vSwitchId'        => $vSwitchId,
            ]);
            $result = $this->client->associateRouteTable($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }
    public function routeTableUnAssociate(string $routeTableId,string $vSwitchId,$regionId=''):bool{
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);
        $vSwitchId = trim($vSwitchId);
        if(!$routeTableId || !$vSwitchId){
            return false;
        }
        try{
            $request = new UnassociateRouteTableRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
                'vSwitchId'        => $vSwitchId,
            ]);
            $result = $this->client->unassociateRouteTable($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }
    public function routeEntryCreate(string $routeTableId,string $destinationNetwork,string $nextHopId,$nextHopType='Instance',$regionId=''):bool
    {
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);
        $destinationNetwork = trim($destinationNetwork);
        $nextHopId = trim($nextHopId);
        $nextHopType = trim($nextHopType);
        if(!$routeTableId || !$destinationNetwork || !$nextHopId){
            return false;
        }
        try{
            $request = new CreateRouteEntryRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
                'destinationCidrBlock'        => $destinationNetwork,
                'nextHopId'        => $nextHopId,
                'nextHopType'        => $nextHopType,
            ]);
            $result = $this->client->createRouteEntry($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }
    public function routeEntryDelete(string $routeTableId,string $destinationNetwork=null,$regionId=''):bool
    {
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);
        if(!$routeTableId){
            return false;
        }
        try{
            $request = new DeleteRouteEntryRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
                'destinationCidrBlock'        => $destinationNetwork,
            ]);
            $result = $this->client->deleteRouteEntry($request);

            return (bool)$result->body->toMap();
        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return false;
    }
    public function routeEntryListDescribe(string $routeTableId,$regionId=''):array
    {
        $regionId = $this->getRegionId($regionId);
        $routeTableId = trim($routeTableId);
        if(!$routeTableId){
            return [];
        }
        $models = [];
        try{
            $request = new DescribeRouteEntryListRequest([
                'regionId'        => $regionId,
                'routeTableId'        => $routeTableId,
                'routeEntryType'        => 'Custom',
            ]);
            $result = $this->client->describeRouteEntryList($request);

            $data = (array)UtilArr::get($result->body->toMap(), 'RouteEntrys.RouteEntry');

            foreach ($data as $datum){
                $id = UtilArr::get($datum,'RouteEntryId');
                if(!$id){
                    continue;
                }
                $models[] = ["id"=>$id,"destination_network"=>UtilArr::get($datum,'DestinationCidrBlock')];
            }

        }catch (\Exception $exception){
            $this->setError($exception->getMessage());
        }
        return $models;
    }

}
